<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/cloudiary.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Cloudiary</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script type="text/javascript" src="Js/jquery.js"></script>
<script type="text/javascript" src="Js/slider.js"></script>
<!-- InstanceEndEditable -->
<link href="CSS/css.css" rel="stylesheet" type="text/css" />
</head>
<?php
include('userlock.php');

if($_SERVER["REQUEST_METHOD"] == "GET")
{ 
	$_SESSION['viewID'] = $_GET['id'];
	$postid = $_SESSION['viewID'];	
}
else
{
	if(isset($_SESSION['viewID'])){
    $postid = $_SESSION['viewID'];}
    
	else{echo "Cannot apply session";}
}

if($_SERVER["REQUEST_METHOD"] == "POST")
{
	if(!empty($_POST['comment']))
	{
		$mycomment=addslashes($_POST['comment']);
		$mycomment=trim($mycomment);
		
		if($mycomment != ""){
		$hour= date("H") + 6;
		if($hour > 23)
		{
		$hour = $hour - 24;
		}
		$writedate = date("Y-m-d");
		$writetime = date("$hour:i:s");
		mysql_query("INSERT INTO comment (comment,comment_date,comment_time,post_ID,friend_email) VALUES ('$mycomment','$writedate','$writetime','$postid','$login_session')");
		}
	}
}

$sql="SELECT * FROM post WHERE post_ID ='$postid'";
$sql2="SELECT * FROM comment WHERE post_ID ='$postid'";

$result=mysql_query($sql);
$result2=mysql_query($sql2);

$row=mysql_fetch_array($result);
$row2=mysql_query("SELECT user_name FROM user where user_email = '".$row['user_email']."'");
$row2=mysql_fetch_array($row2);
?>

<body>
<div id="container">
<div id="wrapper">

<div id="header">
<!-- InstanceBeginEditable name="header" -->
<div class="welcome">
<?php include('welcomeuser.php');?>
</div>
<!-- InstanceEndEditable -->

<img src="Assets/cloud diary low-01(trans).png" alt="CloudDiary" width="75" height="45" style="padding:5px 10px;" /> <br />
</div>

<div id="main">
<!-- InstanceBeginEditable name="main" -->
<ul class="dropdown">
<li><a href="Home.php" class="linkStraight">Home &nbsp; &nbsp;</a></li>
<li><a href="#" class="linkDown" id="classification">Classifications &nbsp; &nbsp;</a>
	<ul class="sub_menu" id="menu1">
    <li> <a href="PublicClassification.php"> Public &nbsp; </a> </li>
    <li> <a href="FriendClassification.php"> Friend &nbsp; </a> </li>
    </ul>
</li>
<li><a href="#" class="linkDown" id="friends">Friends &nbsp; &nbsp;</a>
	<ul class="sub_menu" id="menu2">
    <li> <a href="Friends.php"> Search Friends &nbsp; </a> </li>
    <li> <a href="CurrentFriends.php"> Current Friends &nbsp; </a> </li>
    <li> <a href="Send.php"> Sending Request &nbsp; </a> </li>
    <li> <a href="Receive.php"> Pending Request &nbsp; </a> </li>
    </ul>
</li>
<li><a href="#" class="linkDown" id="posts">Posts &nbsp; &nbsp;</a>
	<ul class="sub_menu" id="menu3">
    <li> <a href="NewPost.php"> New Post &nbsp; </a> </li>
    <li> <a href="ViewPosts.php">  View All Posts &nbsp; </a> </li>
    </ul>
</li>
<li><a href="Privacy.php" class="linkStraight">Privacy Settings &nbsp; &nbsp;</a></li>
</ul>

<div id="content">
<div id="profileContainer">
	<div id="post">
	<table border="0" width="100%" style="margin-left:auto; margin-right:auto;">
	<?php
	echo"<tr> <td width='150' align='center' rowspan='3'>";
	echo"<img src='display_photo.php?id=".$row['user_email']."' alt='User picture'  width='150' height='170' style='border:1px solid #69F; padding:2px' /> </td>";
	echo"<td width='20' rowspan='3' style='border-right:solid 1px #69F'> &nbsp; </td>";
	?>
    <td colspan="3" valign="top"> <p style="font-size:16px;font-weight:bold"> &nbsp; <?php echo $row['post_topic'];?> </p>
     &nbsp;
	<?php echo $row['post'];?>
	</td> </tr>
	<tr> <td align="right" colspan="3">
	<form method="post" action="EditPost.php">
	<input type="hidden" name="editID" value="<?php echo $row['post_ID']?>"/>
	<input type="image" src="Assets/buttonEdit.png" value="Edit" />  
	&nbsp; </td> </tr>
	</form>
	<tr>
	<td align="center" height="5px" style='color:#999; font-size:11px'> Posted By <?php echo $row2['user_name']?> </td>
	<td align="center" height="5px" style='color:#999; font-size:11px'> Posted Date <?php echo $row['post_date'];?> </td>
	<td align="center" height="5px" style='color:#999; font-size:11px'> Posted Time <?php echo $row['post_time'];?> </td>
	</tr>
    </table>
    </div>

    <p> &nbsp; Write your comment: <br /></p>
	<form method="post">
    &nbsp; <textarea name="comment" style="width:98%" rows="7" placeholder="Write Your Comment Here... "></textarea>
    <p align="right" style="padding-right:10px"> <input type="image" src="Assets/buttonSubmit.png" value="Submit" /> &nbsp; </p>
	</form>
        
    <span>
    <table border="0" width="100%" align="center">
    
    <?php
	
	while($data_fetch=mysql_fetch_array($result2))
	{
	echo "<tr>";
    echo "<td width='25' rowspan='4'>&nbsp;  </td>";
    echo "<td colspan='6'>&nbsp;  </td> ";
    echo "<td width='25' rowspan='4'>&nbsp;  </td>";
    echo "</tr>";
	echo "<tr> <td width='90' height='90' rowspan='2' style='border:solid 1px #69F; padding:2px;' align='center'>";
    echo "<img src='display_photo.php?id=".$data_fetch['friend_email']."' width='90px' height='100px' />";
    echo "</td>";
    echo "<td width='21' rowspan='2' style='border-right:solid 1px #69F'> </td>";
    echo "<td width='530' height='62' colspan='3' > &nbsp; ".$data_fetch['comment']." </td>";
	
	?>
    
    
    <td align="right" width="150" rowspan="2">
	<form name="delete" action="SQL.php" method="POST" class="delete_button">
    <input type="hidden" name="query" value="<?php echo "DELETE FROM comment WHERE comment_ID='".$data_fetch['comment_ID']."'"; ?>"/>
	<input type="hidden" name="location" value="<?php echo "Post.php?id=".$row['post_ID'].""; ?>"/>
    <input type="image" src="Assets/buttonDelete.png" value="Delete" />
    </form>
	</td>
	</tr>
    
	<?php
	echo"<tr>"; 
	echo"<td width='265' height='20px' align='center' style='color:#999; font-size:11px'> &nbsp; Posted on ".$data_fetch['comment_date']."</td>";
	echo"<td width='265' height='20px' align='center' style='color:#999; font-size:11px'> &nbsp; Posted on ".$data_fetch['comment_time']."</td>";
	$fetch=mysql_query("SELECT user_name from user where user_email='".$data_fetch['friend_email']."'");
	$fetch=mysql_fetch_array($fetch);
    echo"<td align='center' width='265' height='20px' style='color:#999; font-size:11px'> Posted by ".$fetch['user_name']."&nbsp; &nbsp; </td>";
    echo"</tr>";
	echo"<tr> <td colspan='6'  style='border-bottom:solid 1px #69F;'>&nbsp;  </td> </tr>";
	}
	?>
    
    </table>
    </span>
    </div>

</div>
<!-- InstanceEndEditable -->
</div>

</div>
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 CloudDiary </p>
</div>
</body>
<!-- InstanceEnd --></html>
